#作业实验8 三小题
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep
from selenium.webdriver.common.keys import Keys #特殊键盘输入导包
import random#随机数
from selenium.webdriver.common.action_chains import ActionChains#鼠标悬停

op = webdriver.ChromeOptions()
op.add_experimental_option('excludeSwitches', ['enable-automation'])
op.add_experimental_option('useAutomationExtension', False)
op.add_argument("--start-maximized")#窗口最大化
#打开Chrome浏览器
driver = webdriver.Chrome(options=op)

driver.get(r"https://jqueryui.com/slider/#hotelrooms")

#特殊操作
iframe = driver.find_element(By.CSS_SELECTOR, "#content > iframe")
driver.switch_to.frame(iframe)

# 随机数选择下拉列表
search=driver.find_element(By.CSS_SELECTOR, "#minbeds")
search.click()
sleep(2)
randNumber=random.randint(1,6)#1-6个下拉列表随机选
for i in range(randNumber):
 search.send_keys(Keys.DOWN)
 sleep(1)
value1 = search.get_attribute("value")
search.send_keys(Keys.ENTER)
sleep(3)

ele1=driver.find_element(By.CSS_SELECTOR,"#slider > span")#横向元素
chains=ActionChains(driver)
sleep(1)
chains.drag_and_drop_by_offset(ele1,xoffset=100,yoffset=0).perform()#横向拖动
sleep(2)

driver.quit()